/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fwdispstartscreen;

import fwdispstartscreen.Updater.Version;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import mainGUI.MainFrame;
import updater.Updater;

/**
 *
 * @author rbs
 */
public class StartScreenInit {
    private Updater updater;
    private boolean isError = false;
    private StartFrame start;

    public StartScreenInit() throws MalformedURLException, IOException {
        start = new StartFrame();
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

        start.setLocation((screen.width - 640)/2, (screen.height - 480) / 2);

        boolean isActual = Version.isActualVersion("http://www-user.tu-chemnitz.de/~rbs/updates/fwdisp_ver.txt", "ver.txt", start, this);
        if (!isActual && !isError)
           try {
                updater = new Updater("http://www-user.tu-chemnitz.de/~rbs/updates/fwdisp.zip", start);
                updater.download();
            } catch (IOException ex) {
                Logger.getLogger(StartFrame.class.getName()).log(Level.SEVERE, "Fehler beim initialisieren des Updates.", ex);
            }
        else if (!isError)
        {
            continueToMain();
        }

        if (isError)
        {
            Countdown countdown = new Countdown(start, this);
        }
    }

    public void setErrorTrue()
    {
        isError = true;
    }

    public void continueToMain()
    {
        new MainFrame();
        start.setVisible(false);
        start.dispose();
    }
}
